home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1998 January: Mac OS SDK / Dev.CD Jan 98 SDK2.toast / Development Kits (Disc 2) / QuickTime™ IC SDK 1.01 / Sample Code / QTICSampleApp / Sources / menus.c < prev    next >
Encoding:
Text File  |  1997-06-06  |  7.3 KB  |  294 lines  |  [TEXT/CWIE]

  1. //========================================================================
  2. // Application:        QTICSampleApp
  3. //
  4. // Description:        This application demonstrates the integration of
  5. //                    QuickTime™ IC functionality.
  6. //
  7. // Author:            Mike Bitz
  8. //                     Developer Technical Support
  9. //                     Apple Computer, Inc.
  10. //
  11. // History:            25-Apr-97 original development (mwb)
  12. //
  13. // Copyright © 1997 Apple Computer, Inc., All Rights Reserved
  14. //
  15. // You may incorporate this sample code into your applications without
  16. // restriction, though the sample code has been provided "AS IS" and the
  17. // responsibility for its operation is 100% yours.  However, what you are
  18. // not permitted to do is to redistribute the source as "DSC Sample Code"
  19. // after having made changes. If you're going to re-distribute the source,
  20. // we require that you make it clear in the source that the code was
  21. // descended from Apple Sample Code, but that you've made changes.
  22. //========================================================================
  23.  
  24.  
  25. #include "prototypes.h"
  26. #include "application.h"
  27. #include <QTIC.h>
  28.  
  29. extern Boolean                                gDone;
  30. extern QTICControls                            gCameraControls;
  31. extern Component                            gPanelComponents[10];
  32. extern short                                gNumPanels, gNumPrefPanels;
  33.  
  34.  
  35. //================= SetupMenus =================
  36. void SetupMenus (void) 
  37. {
  38.     Handle                    hMenuBar = nil;
  39.     MenuHandle                hAppleMenu = nil, hFileMenu = nil;
  40.     short                    numCameras = 0;
  41.     
  42.     // Use our MBAR resource
  43.     hMenuBar = GetNewMBar (kBaseResID);
  44.     if (hMenuBar == nil) 
  45.     {
  46.         DebugStr ("\pMenu bar problems...");
  47.         ExitToShell ();
  48.     }
  49.     SetMenuBar (hMenuBar);
  50.  
  51.     // Set up the Apple menu
  52.     hAppleMenu = GetMHandle (menuApple);
  53.     AddResMenu (hAppleMenu, 'DRVR');
  54.     DrawMenuBar ();
  55.     
  56.     // Disable the Close Window menu item since no windows are visible.
  57.     UpdateCloseWindowItem ();
  58.     
  59.     // If only one camera component is installed, disable the "Select Camera" menu item.
  60.     hFileMenu = GetMHandle (menuFile);
  61.     numCameras = NumberOfInstalledCameras ();
  62.     if (numCameras == 1)
  63.     {
  64.         DisableItem (hFileMenu, itemSelectCamera);
  65.     }
  66.     else
  67.     {
  68.         // More than one component is installed, so disable the "show main panel" item.
  69.         DisableItem (hFileMenu, itemDisplayMainPanel);
  70.     }
  71.     
  72.     // Update the menu list of available panels
  73.     UpdatePanelListMenu ();
  74. }
  75.  
  76. //================= HandleMenuChoice =================
  77. void HandleMenuChoice (long menuChoice) 
  78. {
  79.     short        menu, item;
  80.  
  81.     if (menuChoice != 0) 
  82.     {
  83.         menu = HiWord (menuChoice);
  84.         item = LoWord (menuChoice);
  85.         
  86.         switch (menu) 
  87.         {
  88.             // Dispatch to the appropriate menu-handling function.
  89.             case menuApple:
  90.                 HandleAppleMenuChoice (item);
  91.                 break;
  92.                 
  93.             case menuFile:
  94.                 HandleFileMenuChoice (item);
  95.                 break;
  96.                 
  97.             case menuEdit:
  98.                 HandleEditMenuChoice (item);
  99.                 break;
  100.                 
  101.             case menuPanels:
  102.                 HandlePanelListChoice (item);
  103.                 break;
  104.             
  105.             default:
  106.                 HandlePanelSpecificChoice( menu, item );
  107.                 break;
  108.         }
  109.         HiliteMenu (0);
  110.     }
  111. }
  112.  
  113. //================= HandleAppleMenuChoice =================
  114. void HandleAppleMenuChoice (short item) 
  115. {
  116.     OSErr                err = noErr;
  117.     MenuHandle            hAppleMenu = nil;
  118.     Str255                accessoryName;
  119.     short                accessoryNumber;
  120.     
  121.     switch (item) 
  122.     {
  123.         case itemAboutQTIC:
  124.             // Display the QTIC about box
  125.             err = QTICCAboutBox (gCameraControls);
  126.             if (err != noErr)
  127.                 QTICCReportError (gCameraControls, "\pQTICCAboutBox failed", err);
  128.             break;
  129.             
  130.         case itemAboutSampleApp:
  131.             // Display application-specific about box
  132.             HandleMyAboutBox ();
  133.             break;
  134.             
  135.         default:
  136.             // Handle selection of Apple menu items
  137.             hAppleMenu = GetMHandle (menuApple);
  138.             GetItem (hAppleMenu, item, accessoryName);
  139.             accessoryNumber = OpenDeskAcc (accessoryName);
  140.             break;
  141.     }
  142. }
  143.  
  144. //================= HandleFileMenuChoice =================
  145. void HandleFileMenuChoice (short item) 
  146. {
  147.     OSErr            err = noErr;
  148.     MenuHandle        hFileMenu = nil;
  149.  
  150.     switch (item) 
  151.     {
  152.         case itemSelectCamera:
  153.             // Select a camera if there are multiple 'cmra' components installed.
  154.             err = QTICCSelectCamera (gCameraControls);
  155.             if (err == noErr)
  156.             {
  157.                 // Place camera panel item in our menu
  158.                 UpdatePanelListMenu ();
  159.                 
  160.                 // User selected a default camera, so enable the "show main panel" item.
  161.                 hFileMenu = GetMHandle (menuFile);
  162.                 EnableItem (hFileMenu, itemDisplayMainPanel);
  163.             }
  164.             break;
  165.             
  166.         case itemDisplayMainPanel:
  167.             // Display the main panel for the selected camera component.
  168.             err = (OpenMainPanel ());
  169.             if (err != noErr)
  170.             {
  171.                 QTICCReportError (gCameraControls, "\pOpenMainPanel failed", err);
  172.             }
  173.             break;
  174.  
  175.         case itemCloseWindow:
  176.             // Close the window properly (deal with both QTIC and normal windows),
  177.             // then be sure to update the panel window in case we closed a panel.
  178.             err = CloseAppWindow ();
  179.             UpdatePanelSpecificMenu ();
  180.             
  181.             break;
  182.  
  183.         case itemQuit:
  184.             gDone = true;
  185.             break;
  186.     }
  187. }
  188.  
  189. //================= HandleEditMenuChoice =================
  190. void HandleEditMenuChoice (short item) 
  191. {
  192.     switch (item) 
  193.     {
  194.         // Edit menu items not yet implemented...
  195.         case itemUndo:        
  196.             break;
  197.             
  198.         case itemCut:        
  199.             break;
  200.             
  201.         case itemCopy:        
  202.             break;
  203.             
  204.         case itemPaste:        
  205.             break;
  206.             
  207.         case itemClear:        
  208.             break;
  209.     }
  210. }
  211.  
  212. //================= HandlePanelListChoice =================
  213. void HandlePanelListChoice (short item) 
  214. {
  215.     OSErr            err = noErr;
  216.     MenuHandle        hPanelListMenu = nil, hFileMenu = nil;
  217.  
  218.     if (gCameraControls != nil) 
  219.     {
  220.         hPanelListMenu = GetMHandle (menuPanels);
  221.         hFileMenu = GetMHandle (menuFile);
  222.         
  223.         if (item <= gNumPanels)
  224.         {
  225.             // selected item before the divider (template panel, etc.)
  226.             err = QTICCDoAction (gCameraControls, kQTICActionIsPanelOpenByComponent, 
  227.                                 (void *)gPanelComponents[item - 1], nil, nil, nil);
  228.             if (err == 0) 
  229.             {
  230.                 // Panel is already open.  Close it.
  231.                 err = QTICCDoAction (gCameraControls, kQTICActionClosePanelByComponent, 
  232.                                     (void *)gPanelComponents[item - 1], nil, nil, nil);
  233.                 QTICCIdle (gCameraControls);
  234.             } 
  235.             else if (err == 1) 
  236.             {
  237.                 // Panel is currently closed.  Open it.
  238.                 err = QTICCDoAction (gCameraControls, kQTICActionOpenPanelByComponent, 
  239.                                     (void *)gPanelComponents[item - 1], nil, nil, nil);
  240.             }
  241.         }
  242.         else
  243.         {
  244.             // selected item after the divider (preference panel)
  245.             err = QTICCDoAction (gCameraControls, kQTICActionOpenPanelByComponent, 
  246.                                 (void *)gPanelComponents[item - 1], nil, nil, nil);
  247.         }
  248.  
  249.         UpdateCloseWindowItem ();
  250.         UpdatePanelSpecificMenu ();
  251.     }
  252. }
  253.  
  254. //================= HandlePanelSpecificChoice =================
  255. void HandlePanelSpecificChoice (short menuID, short item) 
  256. {
  257.     OSErr            err = noErr;
  258.     MenuHandle        hTempMenu = nil;
  259.     WindowPtr        frontWindow = nil;
  260.     
  261.     frontWindow = FrontWindow ();
  262.     
  263.     hTempMenu = GetMHandle(menuID);
  264.     if (hTempMenu != nil)
  265.     {
  266.         err = QTICCDoCustomMenu (gCameraControls, frontWindow, hTempMenu, item);
  267.         if (err != noErr)
  268.         {
  269.             // Use the QTIC facilities to report the error
  270.             QTICCReportError (gCameraControls, "\pQTICCDoCustomMenu failed", err);
  271.         }
  272.     }
  273. }
  274.  
  275. //================= UpdateCloseWindowItem =================
  276. void UpdateCloseWindowItem (void) 
  277. {
  278.     WindowPtr        frontWindow = nil;
  279.     MenuHandle        hFileMenu = nil;
  280.     
  281.     frontWindow = FrontWindow ();
  282.     hFileMenu = GetMHandle (menuFile);
  283.     
  284.     if (frontWindow == nil)
  285.     {
  286.         // Disable the Close Window menu item since no more windows are visible.
  287.         DisableItem (hFileMenu, itemCloseWindow);
  288.     }
  289.     else
  290.     {
  291.         // Enable the Close Window menu item since at least one window is visible.
  292.         EnableItem (hFileMenu, itemCloseWindow);
  293.     }
  294. }